package Dungeoneering.Puzzles;

import org.powerbot.game.api.methods.tab.Inventory;
import org.powerbot.game.api.wrappers.node.Item;

import Dungeoneering.ActionHandlers.ActionHandler;
import Dungeoneering.Entities.Room;
import Dungeoneering.Utils.Utilities;

public class KeystoneBridge extends PuzzleStrategy{

	private final int gap = 54187;
	private final int finishedBridge = 54191;
	private final int miningRock = 54183;
	private final int rock = 19660;
	private final int keystone = 19661;
	
	@Override
	public boolean detect(Room room) {
		if(room.containsLocations(gap))
			return true;
		return false;
	}

	@Override
	public void solve(Room room) {
	// TODO solve it :p
		if(!detect(room))
		//TODO write an error message
			return;
		
		Item rockItem;
		
		Utilities.thinkSleep();
		
		status = Status.TRYING_SKILL_ROOM;
		
		while(room.containsLocations(gap)) {
			ActionHandler.walkNearLocation(room.getNearestLocation(miningRock));
		
			while(Inventory.getCount(keystone) == 0) {
				while(Inventory.getCount(rock) == 0) {
					ActionHandler.interactLocation(room.getNearestLocation(miningRock), "Mine");
					Utilities.randSleep(800);
				}
				
				Item[] items = Inventory.getItems();
				for(Item i : items) {
					if(i.getId() == rock) {
						rockItem = i;
						break;
					}
				}
				ActionHandler.interactInventoryItem((Inventory.getItems())[0], "Carve");
				Utilities.randSleep(800);
			}
		
			ActionHandler.interactLocation(room.getNearestLocation(gap), "Repair");
			Utilities.randSleep(2000);
		}
		
		//TODO Open Door
		
		status = Status.OPENING_DOOR;
	}
}
